package main

import (
	"encoding/json"
	"fmt"
	"net/http"

	"gitee.com/shiwjlinux/gserror/common"
	"gitee.com/shiwjlinux/gserror/info"
)

func main() {
	// json.Unmarshal()
	// 发送GET请求
	resp, err := http.Get(info.AgentInfoUrl)
	if err != nil {
		fmt.Printf("%s Error sending GET request:%v\n", common.NowTime(), err)
		return
	}
	defer resp.Body.Close()

	// 解析响应
	ag := info.NewAgentInfo()

	err = json.NewDecoder(resp.Body).Decode(&ag)
	if err != nil {
		fmt.Printf("%s Error parsing JSON: %v\n", common.NowTime(), err)
		return
	}

	for _, gs := range ag.GS {
		// fmt.Println(gs.String())
		if gs.StatusError() == nil {
			fmt.Printf("%s gs %s status is %s\n", common.NowTime(), gs.GSID, gs.Status)
			continue
		}

		if err := gs.Kill(); err != nil {
			fmt.Printf("%s failed to kill gs %s: %v\n", common.NowTime(), gs.GSID, err)
		}

	}
}
